<template>
	<view class="hwq-content">
		<navBar title="险情事件" @goBack="goBack"></navBar>
		<scroll-view scroll-y="true" class="hwq-scroll-box">
			<view class="view-box">
				<view class="item-box" v-for="item in list" :key="item.id">
					<view class="top-box">
						<view class="left-box">
							<view class="title">{{item.bizProjectName}}</view>
							<view class="time">{{item.startTime2}}</view>
						</view>
						<view class="right-box">
							<image class="img" mode="aspectFill" src="/static/image/emergency/Group%202259.png"></image>
						</view>
					</view>
					<view class="bottom-box">
						<view class="share-addr" @click="shareBtn(item)">
							分享地址
						</view>
						<view class="danger" @click="report(item)">
							上报险情
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		getListByNameByLike
	} from "@/api/emergency/emergencyDispatch.js"
	import mixin from "@/utils/mixins.js"
	import {
		getToken
	} from '@/utils/auth'
	export default {
		data() {
			return {
				list: []
			}
		},
		mixins: [mixin],
		onLoad(options){
			this.eventId=Number(options.eventId)
			this.getListByNameByLike()
		},
		methods: {
			goBack(){
				uni.switchTab({
					url:"/pages/homePage/homePage"
				})
			},
			//点击上报险情按钮
			report(item) {
				uni.navigateTo({
					url: '/pages/emergency/reportEmergency',
					events:{
						getList:()=>{
						this.getListByNameByLike()
						}
					},
					success: res => {
						res.eventChannel.emit('setData', {
							data: item
						})
					},
				});
			},
			//分享按钮点击事件 todo
			shareBtn(item) {
				let projectId = uni.getStorageSync("isOwner") || ""
				let value = this.$config.SHARE_URL + `?token=${getToken()}&id=${item.id}&projectId=${projectId}&page=updateDanger`
				uni.setClipboardData({
					data: value, //要被复制的内容
					success: () => { //复制成功的回调函数
						uni.showToast({ //提示
							title: '复制成功'
						})
					}
				});
			},
			// 获取事件列表
			getListByNameByLike() {
				let _query = {
					currPage: 1,
					pageSize: 100000,
					params: {
						orgId: "", // 组织id
						state: 0,
					}
				}
				getListByNameByLike(_query).then(res => {
					if (res.success) {
						res.result.list.forEach(item => {
							item.startTime2 = this.getDate2(item.startTime)
						})
						this.list = res.result.list.filter(item=>item.id===this.eventId)
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.hwq-content {
		padding: 0;

		/deep/ .navBar {
			margin-left: 30rpx;
			margin-right: 30rpx;
			box-sizing: border-box;
			width: calc(100% - 60rpx);
		}

		.hwq-scroll-box {
			background-color: #F5F7FA;
		}

		.view-box {
			display: flex;
			align-items: center;
			flex-direction: column;
			padding-top: 23rpx;
			font-family: PingFang SC-Medium, PingFang SC;

			.item-box {
				flex: 1;
				width: 686rpx;
				background-color: #fff;
				margin: 23rpx 0;
				box-shadow: 0rpx 0rpx 20rpx 2rpx rgba(105, 183, 255, 0.25);
				border-radius: 16rpx;

				.top-box {
					display: flex;
					justify-content: space-around;
					align-items: center;
					height: 194rpx;

					.left-box {
						flex: 1;
						max-width: 400rpx;

						.title {
							font-size: 36rpx;
							color: #445469;
						}

						.time {
							font-size: 28rpx;
							color: #6A819E;
							margin-top: 12rpx;
						}
					}

					.right-box {
						flex: 1;
						max-width: 70rpx;

						.img {
							width: 70rpx;
							height: 70rpx;
						}
					}
				}

				.bottom-box {
					display: flex;
					height: 102rpx;
					line-height: 102rpx;
					text-align: center;
					font-size: 32rpx;
					color: #22204E;
					border-top: 2px solid #E2E5ED;

					.danger {
						flex: 1;
					}

					.share-addr {
						flex: 1;
						border-right: 2px solid #E2E5ED;
						box-sizing: border-box;
					}
				}
			}
		}
	}
</style>
